const app = getApp()
import util from '../../utils/util'
import {
  GetGovern,
  GetGovernDetail,
  GetVideoMonitor
} from '../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    gov_id: '',
    type: '',
    active: 0, //当前激活选中项，默认为0
    columns: [], //栏目数组
    MessageList: [],
    video_list: [], //监控视频
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    util.apiRequest(GetGovern, {
      type: 1,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('栏目', r.data.data);
      that.setData({
        columns: r.data.data,
        gov_id: r.data.data[0].id
      });
      console.log(this.data.gov_id)

      this.getList()
    });


  },

  getList() {
    let that = this;
    util.apiRequest(GetGovernDetail, {
      gov_id: that.data.gov_id,
      page: that.data.page,
      limit: that.data.limit,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('列表', r.data.data.data);
      that.setData({
        MessageList: r.data.data.data,
      });

    });
  },

  SwitchStatus: function(e) {
    // 传递的参数
    let index = e.currentTarget.dataset['index'];
    let type = e.currentTarget.dataset['type'];
    // console.log('点击事件传递的参数index：',index);
    console.log('点击事件传递的参数type：', type);
    let that = this;
    that.setData({
      type: type,
      active: index,
    });

    if (type == 'video') {
      that.getVideoList();
    } else {
      util.apiRequest(GetGovernDetail, {
        gov_id: type,
        vollege_id: app.globalData.vollege_id
      }, null).then(r => {
        console.log('选择列表：', r.data.data.data);
        that.setData({
          MessageList: r.data.data.data,
        });
      });
    }
  },

  getVideoList() {
    let that = this;
    util.apiRequest(GetVideoMonitor, {
      type: 2,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('监控视频', r)
      that.setData({
        video_list: r.data.data.data
      })
    })
  },

  // 跳转到内容页
  toNewsDetail: function(e) {
    let id = e.currentTarget.dataset['id'];
    console.log('治理现代化id:', id);
    wx.navigateTo({
      url: '/pages/newsDetail/newsDetail?id=' + id,
    })
  },

  // 跳转视频详情
  toDetail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shipin/shipinDetail/shipinDetail?id=' + id,
    })
  },

  onMsg: function() {
    // console.log('参数type：',this.data.columns[this.data.active].id);
    wx.navigateTo({
      url: '/pages/message/msg_form/msg_form?type=' + this.data.columns[this.data.active].id,
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})